package Simulation;

import fxana.FxRawDataSet;
import fxana.RawDataCell;

public class ConditionLSM2 extends Condition {
	/* This construct is for seed */
	public ConditionLSM2(){
		super();
	}
	public ConditionLSM2(FxRawDataSet ds, RawDataCell today,
			EvaluatorParaFlag flag) {
		super(ds, today, flag);
	}

	@Override
	protected void PreProcess(FxRawDataSet ds, RawDataCell today,
			EvaluatorParaFlag flag) {
	
		if(flag.IsLFlagSet()&&flag.GetLFlagIterator().hasNext()){
			super.LossCutValue=flag.GetLFlagIterator().next()/10.0;
		}
	}

	@Override
	protected Condition GetNew(FxRawDataSet ds, RawDataCell today,
			EvaluatorParaFlag flag) {
		return new ConditionLSM2(ds,today,flag);
	}

	@Override
	protected RawDataCell GetEstimatedValue(FxRawDataSet ds, RawDataCell today,
			EvaluatorParaFlag flag) {
		Integer init_numberofday=25;
		Integer set_numberofday=5;
		Integer numberofday=init_numberofday;
		
		if(flag.IsMFlagSet()&&flag.GetMFlagIterator().hasNext()){
			init_numberofday=flag.GetMFlagIterator().next();
		}
		
		if(flag.IsNFlagSet()&&flag.GetNFlagIterator().hasNext()){
			set_numberofday=flag.GetNFlagIterator().next();
		}
		
		if(this.State==ConditionState.NULL){
			numberofday=init_numberofday;
		}else{
			numberofday=set_numberofday;
		}
		
		RawDataCell est=ds.GetLSMDataByDate(today.GetRecDate(), numberofday);
		return est;
	}
	@Override
	protected void UpdateLossCutValue(FxRawDataSet ds, RawDataCell today,
			EvaluatorParaFlag flag) {
		return;
	}
}
